package com.itany.book.service.impl;

import com.itany.exception.UserErrorException;
import com.itany.exception.UserNotExistException;
import com.itany.mapper.ManagerUserMapper;
import com.itany.pojo.ManagerUser;
import com.itany.pojo.User;
import com.itany.service.ManagerUserService;
import com.itany.vo.CommentUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class ManagerUserServiceImpl implements ManagerUserService {

    @Autowired
    ManagerUserMapper managerUserMapper;

    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public ManagerUser login(String username, String password) throws UserNotExistException, UserErrorException {
        if (CommentUtil.isNull(username) || CommentUtil.isNull(password)){
            throw new UserNotExistException("用户名或者密码不能为空!");
        }
        ManagerUser managerUser = managerUserMapper.selectByParam(username,password);
        if (managerUser == null){
            throw new UserErrorException("用户名或者密码错误!");
        }
        return managerUser;
    }
}
